/*************************************************************************
	> File Name: oj-382_joseph_circle.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年11月02日 星期一 23时27分02秒
 ************************************************************************/

#include <iostream>
using namespace std;

typedef struct _node {
    int id;
    struct _node *next;
} Node;

class Josephus {
private:
    Node *head;
    int cnt;
public:
    Josephus() {
        head = new Node;
        head->next = NULL;
        head->id = 0;
        cnt = 0;
    }
    ~Josephus() {
        Node *tail = head->next;
        Node *current_node = tail->next;
        tail->next = NULL;
        while (current_node->next != NULL) {
            Node *delete_node = current_node;
            current_node = current_node->next;
            delete delete_node;
            delete_node = NULL;
        }
        delete tail;
        tail = NULL;
        delete head;
        head = NULL;
    }
    void delete_times(int times) {
        Node *current_node = head->next;
        while (cnt > 1) {
            for (int i = 1; i < times; ++i) {
                current_node = current_node->next;
            }
            Node *delete_node = current_node->next;
            current_node->next = current_node->next->next;
            delete delete_node;
            delete_node = NULL;
            cnt--;
        }
        head->next = current_node;
    }
    void insert_a_node() {
        Node *node = new Node;
        node->id = cnt + 1;
        if (cnt == 0) {
            head->next = node;
            node->next = node;
        }
        else {
            Node *p = head->next;
            node->next = p->next;
            p->next = node;
            head->next = node;
        }
        cnt++;
    }
    void output() {
        if (cnt == 0) return ;
        Node *current_node = head->next;
        for (int i = 0; i < cnt; ++i) {
            current_node = current_node->next;
            cout << current_node->id << endl;
        }
    }
    int get_cnt() {
        return cnt;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    Josephus jos;
    for (int i = 0; i < n; ++i) {
        jos.insert_a_node();
    }
    jos.output();
    jos.delete_times(m);
    jos.output();
    return 0;
}
